﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using gfPage;
using gfLibrary;
using DBUtility;
using Config;
using Model;
using BLL;

namespace GreatGF
{
    public partial class CALIB_LOG_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             gfAjaxJs.SetNoCache();

             if (Page.IsPostBack == false)
             {
                 btnSearch_Click(sender, e);
             }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strKeywords = txtKeywords.Text;

            string strSql = "select * from CALIB_LOG";

            if (strKeywords.Length > 0)
            {
                strSql += " where ";
                strSql += "ID like '%" + strKeywords + "%'";
                strSql += " or JCXH like '%" + strKeywords + "%'";
                strSql += " or CalibName like '%" + strKeywords + "%'";
                strSql += " or StartTime like '%" + strKeywords + "%'";
                strSql += " or EndTime like '%" + strKeywords + "%'";
                strSql += " or DetailedData like '%" + strKeywords + "%'";

            }

            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, AppConfig.g_strConnectionStringSqlClient, strSql, 20);

            gfLibrary.gfString vString = new gfString();
            for (int i = 0; i < m_dtTable.Rows.Count; i++)
            {
                m_dtTable.Rows[i]["DetailedData"] = vString.GetLeftLengthString(m_dtTable.Rows[i]["DetailedData"].ToString(), 70);
            }

            rptList.DataSource = m_dtTable;
            rptList.DataBind();

            m_dtTable.Dispose();
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;
            btnSearch_Click(sender, null);
         }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void btnBrowse_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if((strUniqueKey == null)||(strUniqueKey.Length == 0)||(gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }

            Response.Redirect("CALIB_LOG_Insert_Update.aspx?m=b&UniqueKey=" + strUniqueKey);
        }
    }
}
